import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { AccessPointM } from "@/api/backend/index";
import { ElNotification } from "element-plus"; //处理导航信息

export const useAccessPoint = defineStore(Names.AccessPointM, {
  state: () => {
    return {
      single: {
        bank: null,
        bankOne: null,
        cardNumber: "",
        cmdName: "",
        code: "",
        createBy: null,
        createTime: "",
        createUser: null,
        id: 3,
        mgttName: "",
        mgttPassword: "",
        mqttAddr: "",
        mqttPort: "",
        params: {},
        remark: null,
        searchValue: null,
        stateName: "",
        topic: "",
        type: "",
        updateBy: null,
        updateTime: "",
        updateUser: null,
      },
    };
  },
  getters: {},
  actions: {
    //获取网关列表数据
    getIOTList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(
          AccessPointM + "/list",
          { pageNum: 1, pageSize: 1000, ...filter },
          "",
          ""
        )
          .then(async (res: any) => {
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    //解绑网关
    unbind(code: any) {
      return new Promise((resolve, reject) => {
        _get(AccessPointM + "/unbind/" + code, {}, "json", "")
          .then(async (res: any) => {
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    //修改网关状态
    changeStatus(data: any) {
      return new Promise((resolve, reject) => {
        _put(AccessPointM, { data }, "json", "")
          .then(async (res: any) => {
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    
  },
});
